<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div {
      width: 300px;
      height: 40px;
      border: 1px solid pink;
      text-align: center;
      line-height: 40px;
    }
  </style>
</head>

<body>
  <div></div>

  <script>
const div =document.querySelector('div')
function getDateTime (){
    const date = new Date()
    const year =date.getFullYear()
    const month = date.getMonth() +1
    const day = date.getDate()
    let h = date.getHours()
    h = h<10 ? '0' +h :h
    let m = date.getMinutes()
    m = m<10 ? '0' +m :m
    let s =date.setSeconds()
    s = s<10 ? '0' +s :s

    div.innerHTML=`现在是${year}年${month}月${day}日 ${h}:${m}:${s}`;
}
getDateTime()
setInterval(getDateTime,1000)

    // 实现电子时间效果，在div里显示 现在是2024年11月21日 10:12:07 格式的时间


  </script>
</body>

</html>